<template>
  <el-container>
    <el-header>
      <div class="left-panel">
        <fsButton ref="button" plain size="default" :buttons="buttons" @clickHandler="buttonHandler"></fsButton>
      </div>
      <div class="right-panel">
        <ex-search ref="search" :searches="searches" @searchOk="searchHandler" default-code="name" placeholder="请输入名称"></ex-search>
      </div>
    </el-header>
    <el-main class="nopadding">
      <el-container>
        <el-main class="nopadding">
          <ex-table id="exportTable" ref="table" :columns="columns" :url="this.$API.system.export.list.url" :refs="this.$refs" search="search" @columnClick="columnClickHandler"></ex-table>
        </el-main>
      </el-container>
    </el-main>
  </el-container>
  <view-dialog ref="viewDialog"/>
</template>

<script>
import viewDialog from './view'
import ExTable from "@/components/exTable/index.vue";
import ExSearch from "@/components/exSearch/index.vue";
import BaseTemplate from "@/utils/baseTemplate";

export default {
  name: '导出中心管理',
  components: {
    viewDialog,
    ExSearch,
    ExTable,
  },
  data() {
    return {
      buttons: [
        {name: this.$t('button.export'), icon: "el-icon-download", click: "export", permission: "export"},
      ],
      searches: [
        { type: "input", name: "名称", code: "name", placeholder: "请输入名称", maxlength: 30, showLimit: true},
        {type: "radio", name: "导出状态", code: "status",dictCode:'EXPORT_STATUS'},
      ],
      columns: [
        {code: "操作", name: "操作", width: "70",click:"download",fixedValue:this.$t('button.down')},
        {code: "name", name: "名称", width: "",click: "show1"},
        {code: "status", name: "导出状态", width: "100", sortable: true, formatter: "DICT", key: "EXPORT_STATUS"},
        {code: "createUser", name: "导出人", width: "100", formatter: "DICT", key: "SysUser"},
        {code: "createTime", name: "导出时间", width: "175", sortable: true, formatter: "DATETIME"},
        {code: "description", name: "描述", width: ""},
      ],
      parentLevelCode: null,
    }
  },
  created() {
  },
  mounted() {
  },
  methods: {
    buttonHandler(index, name) {
      this.$options.methods[name](this, index);
    },
    async searchHandler() {
      let queryParams = {pathCode: this.parentLevelCode}
      await this.$refs.table.refresh(queryParams);
    },
    columnClickHandler(name,data){
      this.$options.methods[name](this, data);
    },
    //查看
    show(_this) {
      let row = _this.$refs.table.selectionOne();
      if (!row) {
        return;
      }

      _this.$nextTick(() => {
        _this.$refs.viewDialog.open(row);
      })
    },
    //查看
    async show1(_this,row) {

      _this.$nextTick(() => {
        _this.$refs.viewDialog.open(row);
      })
    },
    //导出
    async export(_this,index) {
      let attachParams = {};
      let exportApi = _this.$API.system.export.export;
      let exTableRef = _this.$refs.table;
      let exportBtnRef = _this.$refs.button;
      let exportBtnIndex = index;
      await BaseTemplate.export(_this, exportApi, attachParams, exportBtnRef, exportBtnIndex, exTableRef);
    },
    download(_this,data){
      if(data.status!=='4'){
        _this.$notify.warning({title:"下载提示",message:"文件不存在"});
      }else{
        _this.$TOOL.file.open(data.attachFile,true,data.name+"-"+data.createTime);
      }
    },
  }
}
</script>
